;
(function($, window, document, undefined) {
    var KeywordCard = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons'
        };
        this.options = $.extend({}, this.defaults, opts);
    }

    KeywordCard.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == 'true') {
                return me;
            }

            me.bindEvents();


            el.attr('data-initialized', 'true');
            return me;
        },


        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;


            el.delegate('.btn.delete', 'click', function(e) {
                e.preventDefault();

                var elCurrentTarget = $(e.currentTarget);

                $.ajax({
                    url: elCurrentTarget.attr('href'),
                    type: 'delete',
                    dataType: 'json',
                    data: {
                        id: elCurrentTarget.attr('data-id')
                    },
                    success: function(ret) {
                        if (ret && ret.status) {
                            el.remove();
                        } else {

                        }
                    },
                    error: function(ret) {

                    }
                })
            });
        }
    }

    $.fn.KeywordCard = function(opts) {
        var me = this,
            el = me.el,
            comKeywordCard;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comKeywordCard = new KeywordCard(this, opts);
        }

        return comKeywordCard.init();
    }
})(jQuery, window, document);
